﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Workflow;
using MethodWorx.Core.DomainModel;

namespace MethodWorx.CMS.TemplateParser.Installer
{
    public class InstallerWorkflowComponentConfiguration : IWorkflowConfiguration
    {
        public InstallerWorkflowComponentConfiguration(IInstallationWorkflowComponent component)
        {
            this.Component = component;
        }

        public string GetDescriptionSummary()
        {
            return "Component Installation Configuration";
        }

        public IInstallationWorkflowComponent Component { get; private set; }
        public TemplateElement ConfigurationElement { get; set; }
        public Dictionary<string, byte[]> Files { get; set; }

        public byte[] GetParsedFileContents(string file, Dictionary<string, string> variables)
        {
            var s = System.Text.ASCIIEncoding.ASCII.GetString(this.Files[file.ToLower()]);

            foreach(string var in variables.Keys)
            {
                s = s.Replace("{" + var + "}", variables[var]);
            }

            return System.Text.ASCIIEncoding.ASCII.GetBytes(s);
        }
    }
}
